/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MODEL.DAO;

import MODEL.POJO.Parameters;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Quangbt
 */
public class ParametersDao {
    public static Parameters getParameters(){
        Parameters param = null; 
        Session session = HibernateUtil.getSessionFactory().openSession(); 
        try { 
            String hql = "from Parameters"; 
            Query query = session.createQuery(hql); 
            param = (Parameters)query.list().get(0); 
        } catch (HibernateException ex) { 
            System.err.println(ex); 
        } finally { 
            session.close(); 
        } 
        return param; 
    }
    public static boolean updateParameter(Parameters param) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = null;
        try {
            transaction = session.beginTransaction();
            session.update(param);
            transaction.commit();
        } catch (HibernateException ex) {
            //Log the exception
            transaction.rollback();
            System.err.println(ex);
        } finally {
            session.close();
        }
        return true;
    }
}
